<template>
  <el-cascader :value="value" size="mini" :options="options" :props="{value:'id',label:'name'}" separator="-" @change="onChange" />
</template>

<script>
import { transListToTreeData } from '@/utils'
import { getDepartment } from '@/api/department'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      options: []
    }
  },
  async created() {
    const { data } = await getDepartment()
    this.options = transListToTreeData(data, 0)
  },
  methods: {
    onChange(list) {
      if (list.length) {
        this.$emit('input', list[list.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>
